/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.integration.action.user;

import cn.hallele.infrastructure.metadata.io.Page;
import cn.hallele.infrastructure.metadata.io.Response;
import cn.hallele.mc.sdk.usercenter.dto.UserDTO;
import cn.hallele.mc.sdk.usercenter.dto.UserQueryDTO;
import cn.hallele.mc.sdk.usercenter.feign.UserFeign;
import cn.hallele.ms.infrastructure.util.OutGoingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * hallele_ms_portalcenter
 *
 * @author anle5
 * @since 2024/10/6 13:16
 */
@Slf4j
@Service
public class UserIntegrationService {
    @Autowired
    private UserFeign userFeign;

    /**
     * 获取用户信息
     *
     * @param username 用户名
     * @return 用户信息
     */
    public UserDTO queryUserByUsername(String username) {
        Response<UserDTO> response = userFeign.getLoginUser(username);
        return OutGoingUtil.getData(response);
    }

    /**
     * 获取用户头像
     *
     * @param username 用户名
     * @return 用户信息
     */
    public String getAvatar(String username) {
        Response<String> response = userFeign.getAvatar(username);
        return OutGoingUtil.getData(response);
    }

    /**
     * 用户分页查询
     *
     * @param userQueryDTO userQueryDTO
     * @return UserDTO
     */
    public Page<UserDTO> listUser(UserQueryDTO userQueryDTO) {
        Response<Page<UserDTO>> pageResponse = userFeign.listUser(userQueryDTO);
        return OutGoingUtil.getData(pageResponse);
    }
}
